#pragma once

#include "Utilities.h"

bool Utilities::isValidLineIndex(Type::Index::Line lineIndex){
	return lineIndex > 0;
}

bool Utilities::isValidProcIndex(Type::Index::Proc procIndex){
	return	procIndex > 0;
}

bool Utilities::isValidProcName(Type::Name::Proc procName){
	return procName.length() > 0;
}

bool Utilities::isValidVarName(Type::Name::Var varName){
	return	varName.length() > 0;
}

bool Utilities::isValidVarIndex(Type::Index::Var varIndex){
	return	varIndex > 0;
}

bool Utilities::isValidConstant(Type::Constant con){
	return	con >= 0;
}

bool Utilities::isValidNode(TreeNode* node){
	return  node!=NULL && node->getNodeType() != AST_INVALID_TYPE && node->getNodeType() != NULL;
}

bool Utilities::isValidLineEntity(Type::Entity::Line entity){
	return entity != Type::Entity::INVALID_LINE_ENTITY;
}

bool Utilities::isValidBitMap(Type::Map::Bit& bitMap){
	if(!bitMap.empty()){
		unsigned int i;
		unsigned int size = 0;

		for(i=0; i<bitMap.size(); i++){
			Type::List::Bit bits = bitMap.at(i);

			if(size <= 0){
				size = bits.size();
			}

			if(size != bits.size() || size <= 0){
				return false;
			}
		}
		return true;
	}
	return false;
}

bool Utilities::isValidLineMatrix(Type::Map::LineMatrix& lineMatrix){
	if(!lineMatrix.empty()){
		Type::List::Line row = lineMatrix.front();
		return !row.empty();
	}
	return false;
}

bool Utilities::isvalidParentMatrix(Type::Map::ParentMatrix& parentMatrix){
	if(!parentMatrix.empty()){
		Type::Map::ParentMap row = parentMatrix.begin()->second;
		return !row.empty();
	}
	return false;
}

bool Utilities::isValidStartEnd(Type::Index::Line start, Type::Index::Line end){
	if(!isValidLineIndex(start) || !isValidLineIndex(end) || start > end){
		return false;
	}
	
	return true;
}

unsigned int Utilities::getIndexBoundedBySize(unsigned int index, unsigned int size){
	while(index >= size && index > 0){
		index -= size;
	}
	return index;
}